public class Solution {
    public int removeElement(int[] nums, int val) {
        int len=0;
        for(int low=0,high=nums.length-1;low<=high;low++,high--) {
            while(low < high && nums[low] != val) {
                low++;
                len++;
            }
            while(low < high && nums[high] == val) {
                high--;
            }
            nums[low]=nums[high];
            if(low!=high||nums[low]!=val) {
                len++;
            }
        }
        return len;
    }
}